<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <title>微信登录</title>
    <!-- <link rel="dns-prefetch" href="//img.minshengec.com/"> -->
    <!-- <link rel="dns-prefetch" href="//rs.minshengec.com/"> -->
    <link rel="stylesheet" href="css/lib/reset.css">
    <link rel="stylesheet" href="css/wx.css" />
    <script src="js/lib/flexible-163.js"></script>
    <script src="js/lib/jquery-2.2.4.min.js"></script>
    <script src="js/wx.js"></script>
</head>

<body ontouchstart>
    <!-- 返回上一页 -->
    <!-- <div class="go-back"><a href="javascript:void(0)" onclick="history.go(-1)"></a></div> -->

    <div class="wrapper">

        <!-- 主体内容部分s -->
        <div class="container">
       		<p>微信登录</p>    
        </div>
    </div>


<script>
$(function () {

	function getUrlParam(name) {	 
	  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
	  var r = window.location.search.substr(1).match(reg);
	  if (r != null) return unescape(r[2]);
	  return null;
	}



	var code = getUrlParam('code');
	var API = 'https://www.lenmotion.cn/api'
	var URL = encodeURIComponent(window.location.href);
	// console.log(URL)
	if (!code) {
		$.ajax({
		  type: 'GET',
		  url: API + '/weixin/getCodeUrl?redirectUrl=' + URL,
		  dataType: 'json',
		  success: function (res) {
		  	// console.log(res)
		  	window.location.href = res.data
		  },
		  error: function (error) {
		    throw new Error(error)
		  }
		})
	} else {
		$.ajax({
		  type: 'GET',
		  url: API + '/login/login',
		  dataType: 'json',
		  data: {
		    code: code
		  },
		  success: function (data) {
		  	console.log(data)
		  	document.write(data.data.name)		    
		  },
		  error: function (error) {
		    throw new Error(error)
		  }
		})
	}
   

});
</script>

</body>

</html>
